$(function(){
    //点击files换成图片到本地并预览
    $('#inputCover').on('change',function(){
        let files = URL.createObjectURL($(this)[0].files[0]) 
        console.log(files);
        $('.article_cover').attr('src',files)
    })
    
    //点击发布监听事件
    $('.btn-success').on('click',function(){
        
        data()
    })
    
    //封装发布函数
    function data(){
        let form = new FormData($('#form')[0])
        $.ajax({
            url:BigNew.article_publish,
            type:'post',
            data:form,
            dataType:'json',
            processData:false,
            contentType:false,
            success(res){
                //console.log(res);
                if(res.code ==200){
                    alert(res.msg)
                }
            }
        })
    }

    //点击存为草稿监听事件
    $('.btn-default').on('click',function(){
        let form = new FormData($('#form')[0])
        form.append('state','草稿')
        $.ajax({
            url:BigNew.article_publish,
            type:'post',
            data:form,
            dataType:'json',
            processData:false,
            contentType:false,
            success(res){
                console.log(res);
                if(res.code ==200){
                    alert(res.msg)
                }
            }
        })
    })
    
    //类别渲染
    $.ajax({
        url:BigNew.category_list,
        dataType:'json',
        success(res){
            //console.log(res);
            if(res.code == 200){
                $('.category').html(template('mytemp',res))
            }
        }
    })
    
    //时间组件
    jeDate('#articleDate', {
        trigger: 'click',
        theme: { bgcolor: "#ff0000", pnColor: "#00DDAA" },//绿色主题
        format: "YYYY-MM-DD",
        isinitVal: true,
    }) 

    // 富文本框的初始化
    tinymce.init({
        selector: '#articleContent',
        height: '350px',
        language: 'zh_CN',
        browser_spellcheck: true,
        contextmenu: false,
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste imagetools wordcount",
            "code"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
    });

})